<?php
include_once "dbconnect.php";

/* Don't allow normal access */
if (!isset($_GET['activationcode']) ||
    !isset($_GET['email'])||
    !isset($_GET['type']))
{
    $_POST['invalid'] = True;
    header ("Location: index.php");
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
<head>
<style type="text/css">
#checkEmail {
  margin-left: auto;
  margin-right: auto;
  margin-top: 40px;
  padding: 20px;
  width: 400px;
  height: 80px;
  background: #C0C0C0;
  -moz-border-radius: 20px;
  }
</style>
<title>Registration | Activation </title>
<?
$activationcode = mysql_real_escape_string($_GET['activationcode']);
$email = mysql_real_escape_string($_GET['email']);

$type = mysql_real_escape_string($_GET['type']);	//get the type of registration to find whether its user or speaker
//User registration is handled here
if($type=='1')
{
	$query1 = "select * from mukt_users where activationcode='$activationcode' and email='$email'";
	$result = mysql_query($query1) or die('execute query' .mysql_error()) ;
	$no = mysql_num_rows($result) or die("<div id='checkEmail' align='center'>No such account in our database.<br /><a href=\"index.php\">Go to Home Page.</a></div>");
	$row = mysql_fetch_array($result) or die("<div id='checkEmail' align='center'>No such account in our database.<br /><a href=\"index.php\">Go to Home Page.</a></div>");

	if($row['status']) // checking whether the user has already clicked the activation link or not 
		die("<div id='checkEmail' align='center'>Your account has already been activated.<br /><a href=\"index.php\">Go to Home Page.</a></div>");

	if($row && ( $no > 0))
	{
		$query2 = "update mukt_users set activationcode = '',status = 1 where email='$email'";
		// please use where condition to identify confirmed users and unconfirmed users 
		// status = 0 for unconfirmed and status=1 for confirmed users 
		mysql_query($query2) or die ('error ');
		echo "<div id='checkEmail' align='center'> Thank You  $row[loginname]. Your account has been activated!<br />Hope to see you at mukt.in 2008 <br /><a href=\"index.php\">Go to Home Page.</a></div>";
	}
}
//Speaker registration is handled here!
else if($type=='2')
{
	$query1 = "select * from mukt_participants where activationcode='$activationcode' and email='$email'";
	$result = mysql_query($query1) or die('execute query' .mysql_error()) ;
	$no = mysql_num_rows($result) or die("<div id='checkEmail' align='center'>No such account in our database.<br /><a href=\"index.php\">Go to Home Page.</a></div>");
	$row = mysql_fetch_array($result) or die("<div id='checkEmail' align='center'>No such account in our database.<br /><a href=\"index.php\">Go to Home Page.</a></div>");

	if($row['status']) // checking whether the user has already clicked the activation link or not 
		die("<div id='checkEmail' align='center'>Your account has already been activated.<br /><a href=\"index.php\">Go to Home Page.</a></div>");

	if($row && ( $no > 0))
	{
		$query2 = "update mukt_participants set activationcode = '',status = 1 where email='$email'";
		// please use where condition to identify confirmed users and unconfirmed users 
		// status = 0 for unconfirmed and status=1 for confirmed users 
		mysql_query($query2) or die ('error ');
		echo "<div id='checkEmail' align='center'> Thank You  $row[loginname]. Your account has been activated!<br />Hope to see you at mukt.in 2008 <br /><a href=\"index.php\">Go to Home Page.</a></div>";
	}
}
?>
</body>
</html>
